from week3_114.config.config import Base
from selenium.webdriver.common.by import By
import time

class Page(Base):
    # //*[@id="J_user_unLogin"]/span/a
    login_loc = (By.XPATH,'//*[@id="J_user_noId"]/a')
    def login(self):
        self.click(self.login_loc)

    # /html/body/div[2]/div/div[1]/div[1]/div/div[1]/div[2]
    zh_login_loc = (By.XPATH,'/html/body/div[2]/div/div[1]/div[1]/div/div[1]/div[2]')
    def zh_login(self):
        self.click(self.zh_login_loc)

    # name="loginName"
    name_loc = (By.NAME,'loginName')
    def name(self):
        self.send_keys(self.name_loc,'15235688537')

    # name="password"
    password_loc = (By.NAME,'password')
    def password(self):
        self.send_keys(self.password_loc,'Wx03040303.')

    # //*[@id="J_login_form"]/div[6]/div[1]/div[1]/label
    agree_loc = (By.XPATH,'//*[@id="J_login_form"]/div[6]/div[1]/div[1]/label')
    def agree(self):
        self.click(self.agree_loc)

    # #J_login_submit
    dl_button = (By.CSS_SELECTOR,'#J_login_submit')
    def dl(self):
        self.click(self.dl_button)

    # //*[@id="J-search"]/div[1]/input
    search_loc = (By.XPATH,'//*[@id="J-search"]/div[1]/input')
    def search(self):
        self.send_keys(self.search_loc,'智能手机')

    # class="c-search-icon"
    search_button_loc = (By.CLASS_NAME,'c-search-icon')
    def search_button(self):
        self.click(self.search_button_loc)

    get_all_loc = (By.XPATH,'/html/body/div[2]')
    def get_all(self):
        assert '智能手机' in self.get_all_loc

    def luoji_01(self):
        try:
            # https://www.vip.com/
            self.get_url('https://www.vip.com/')
            self.login()
            self.driver.implicitly_wait(10)
            self.zh_login()
            self.name()
            self.password()
            time.sleep(1)
            self.agree()
            time.sleep(5)
            self.dl()
            time.sleep(20)
            self.dl()
            time.sleep(20)
            self.search()
            time.sleep(3)
            self.search_button()
            time.sleep(5)
            print(self.get_all())
            self.driver.save_screenshot('result' + '.png')
        except Exception as e:
            print(e)